package com.ssm.okex.trade.strategy;

import java.util.ArrayList;

/**
 * 2. 均线交叉策略
 */
public class MovingAverageCrossoverStrategy {

    // 判断均线交叉信号
    public static String maCrossoverSignal(ArrayList<Double> ma5, ArrayList<Double> ma10) {
        String signal = "";
        if (ma5.get(ma5.size() - 2) < ma10.get(ma10.size() - 2) && ma5.get(ma5.size() - 1) > ma10.get(ma10.size() - 1)) {
            signal = "BUY";
        } else if (ma5.get(ma5.size() - 2) > ma10.get(ma10.size() - 2) && ma5.get(ma5.size() - 1) < ma10.get(ma10.size() - 1)) {
            signal = "SELL";
        }
        return signal;
    }

    // 主方法
    public static void main(String[] args) {
        ArrayList<Double> prices = new ArrayList<>();
        prices.add(50.0);
        prices.add(60.0);
        prices.add(70.0);
        prices.add(80.0);
        prices.add(90.0);

        ArrayList<Double> ma5 = MovingAverageStrategy.calculateMovingAverage(prices, 5);
        System.out.println("五日均线值: " + ma5);

        ArrayList<Double> ma10 = MovingAverageStrategy.calculateMovingAverage(prices, 10);
        System.out.println("十日均线值: " + ma10);

        String signal = MovingAverageCrossoverStrategy.maCrossoverSignal(ma5, ma10);
        System.out.println("买卖信号: " + signal);
    }
}